/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import model.FactoryModel;
import util.DataUtil;

/**
 *
 * @author ThanhToan
 */
public class FactoryDAO {
    public static ArrayList<FactoryModel> getAllFactory(){
        ArrayList<FactoryModel> facList = new ArrayList<FactoryModel>();
        try {
            CallableStatement csmt = DataUtil.getConnection().prepareCall("{call sp_GetAllFactory()}");
            ResultSet rs = DataUtil.executeStore(csmt);
            while(rs.next()){
                FactoryModel facModel = new FactoryModel();
                facModel.setId("ID");
                facModel.setFacName("FactoryName");
                facModel.setPhone("Phone");
                facModel.setFacDes("Description");
                facModel.setStatus("Status");
                facList.add(facModel);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return facList;
    }

    public static boolean insertFactory(FactoryModel facModel){
        boolean result = false;
        try {
            CallableStatement csmt = DataUtil.getConnection().prepareCall("{call sp_InsertFactory(?,?,?)}");
            csmt.setNString("facName", facModel.getFacName());
            csmt.setNString("phone", facModel.getPhone());
            csmt.setNString("facDes", facModel.getFacDes());
            result = DataUtil.executeNonStore(csmt);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static boolean upadteFactory(FactoryModel facModel){
        boolean result = false;
        try {
            CallableStatement csmt = DataUtil.getConnection().prepareCall("{call sp_UpdateFactory(?,?,?,?,?)}");
            csmt.setString("id", facModel.getId());
            csmt.setNString("facName", facModel.getFacName());
            csmt.setString("phone", facModel.getPhone());
            csmt.setNString("facDes", facModel.getFacDes());
            csmt.setNString("status", facModel.getStatus());
            result = DataUtil.executeNonStore(csmt);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
